Imports ComponentGo.Calendars

Imports Phoenix.DataAccess
Imports Phoenix.Events

Namespace Forms.Area

    Public Class WeekCalendarArea
        Inherits CalendarAreaBase

#Region " Windows Form Designer generated code "

        Public Sub New()
            MyBase.New()

            'This call is required by the Windows Form Designer.
            InitializeComponent()

            'Add any initialization after the InitializeComponent() call
            Calendar = WeeklyCalendar
        End Sub

        'UserControl overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        Friend WithEvents WeeklyCalendar As ComponentGo.Calendars.WeeklyCalendar
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.WeeklyCalendar = New ComponentGo.Calendars.WeeklyCalendar
            Me.SuspendLayout()
            '
            'WeeklyCalendar
            '
            Me.WeeklyCalendar.AllowOverlap = False
            Me.WeeklyCalendar.DateLabelFormat = "{0:ddd d MMMM yyyy}"
            Me.WeeklyCalendar.DayLineColor = System.Drawing.Color.FromArgb(CType(215, Byte), CType(177, Byte), CType(0, Byte))
            Me.WeeklyCalendar.Dock = System.Windows.Forms.DockStyle.Fill
            Me.WeeklyCalendar.EnableEditInPlace = False
            Me.WeeklyCalendar.ExtraBreakHourColor = System.Drawing.Color.Fuchsia
            Me.WeeklyCalendar.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
            Me.WeeklyCalendar.FreeDay = ComponentGo.Calendars.FreeDays.None
            Me.WeeklyCalendar.FreeHourColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(238, Byte), CType(158, Byte))
            Me.WeeklyCalendar.Location = New System.Drawing.Point(0, 0)
            Me.WeeklyCalendar.Name = "WeeklyCalendar"
            Me.WeeklyCalendar.Size = New System.Drawing.Size(360, 448)
            Me.WeeklyCalendar.TabIndex = 0
            '
            'WeekCalendarArea
            '
            Me.Controls.Add(Me.WeeklyCalendar)
            Me.Name = "WeekCalendarArea"
            Me.ResumeLayout(False)

        End Sub

#End Region

#Region " Properties "
        Public Overrides ReadOnly Property HasResources() As Boolean
            Get
                Return False
            End Get
        End Property
#End Region

#Region " Time Navigation "
        Public Overrides Function SetNext() As Date
            WeeklyCalendar.FirstDate = WeeklyCalendar.FirstDate.AddDays(7)
            Return WeeklyCalendar.FirstDate
        End Function
        Public Overrides Function SetPrev() As Date
            WeeklyCalendar.FirstDate = WeeklyCalendar.FirstDate.AddDays(-7)
            Return WeeklyCalendar.FirstDate
        End Function
        Public Overrides Function SetToday() As Date
            WeeklyCalendar.FirstDate = Date.Today
            Return WeeklyCalendar.FirstDate
        End Function

        Public Overrides Function SetDate(ByVal d As Date) As Date
            WeeklyCalendar.FirstDate = d
            Return WeeklyCalendar.FirstDate
        End Function

#End Region

        Public Overrides Property FirstDate() As Date
            Get
                Return WeeklyCalendar.FirstDate
            End Get
            Set(ByVal Value As Date)
                WeeklyCalendar.FirstDate = Value
            End Set
        End Property


        Private Sub WeeklyCalendar_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles WeeklyCalendar.MouseDown
            If e.Clicks < 2 Then Return
            If e.Button <> MouseButtons.Left Then Return
            If Not WeeklyCalendar.Appointments.FirstSelected Is Nothing Then Return

            Dim r As TabularCalendar.Regions = WeeklyCalendar.HitTest(New Point(e.X, e.Y))
            If (r = TabularCalendar.Regions.DaysLabel) Or (r = TabularCalendar.Regions.DaysWorkspace) Then
                AppRaiseEvent(Me, New PhoenixCalendarEventArgs(PhoenixCalendar.DayCalendar, WeeklyCalendar.SelectedDateBegin))
            End If
        End Sub


        Public Overrides Sub Paste(ByVal arr As IList)
            If arr Is Nothing Then
                Return
            End If
            For Each obj As DataRow In arr
                Dim item As DataAccess.DataSetAppointments.Appointment = Helpers.AppointmentHelper.Copy(obj)
                item.StartTime = Calendar.SelectedDateBegin.Add(item.StartTime.TimeOfDay)
                item.FinishTime = item.StartTime.AddMinutes(item.ExpectedDuration)
                If Helpers.AppointmentHelper.IsValidTime(item.StartTime, item.FinishTime, item) Then
                    Helpers.AppointmentHelper.UpdateAppointment(item, Me)
                Else
                    AppointmentForm.OpenForm(item)
                End If
            Next
        End Sub

        Private Sub WeeklyCalendar_FirstDateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles WeeklyCalendar.FirstDateChanged
            OnFirstDateChanged(New DateRangeEventArgs(WeeklyCalendar.FirstDate, WeeklyCalendar.FirstDate))
        End Sub
    End Class

End Namespace